package com.etoak.rst.sys.dish.service.SeriviceImpl;

import com.etoak.rst.sys.dish.DTO.CategoryDTO;
import com.etoak.rst.sys.dish.DTO.DishDTO;
import com.etoak.rst.sys.dish.entity.Category;
import com.etoak.rst.sys.dish.entity.DIsh;
import com.etoak.rst.sys.dish.mapper.DishMapper;
import com.etoak.rst.sys.dish.mapper.DishTypeMapper;
import com.etoak.rst.sys.dish.service.IDishService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@Service
public class DishServiceImpl implements IDishService {

    @Autowired
    DishTypeMapper dao;

    @Autowired
    DishMapper ddao;
    @Override
    public List<Category> querySome(CategoryDTO dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        List<Category> data = dao.querySome(dto);
        return data;
    }

    @Override
    public boolean addCateGory(Category category) {
        category.setCreate_time(new Date());
        category.setUpdate_time(new Date());
        return dao.addCateGory(category)>0;
    }

    @Override
    public boolean updateCategory(Category category) {
        category.setUpdate_time(new Date());
        int flag = dao.updateCategory(category);
        return flag>0;
    }

    @Override
    public boolean delCategory(int cateid) {
        return dao.delCategory(cateid)>0;
    }

    @Override
    public boolean cateStatue(Category category) {
        category.setUpdate_time(new Date());
        return dao.cateStatue(category)>0;
    }

    @Override
    public List<Category> queryAll() {
        return dao.queryAll();
    }

    @Override
    public List<DIsh> querySome4Dish(DishDTO dto) {
        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());
        return ddao.querySome4Dish(dto);
    }

    @Transactional
    @Override
    public void delFoods(List<Integer> ids) {
        ddao.delFoods(ids);
    }

    @Override
    public boolean addDish(DIsh dIsh) {
        dIsh.setCreateTime(new Date());
        dIsh.setUpdateTime(new Date());
        return ddao.addDish(dIsh);
    }
}
